package com.oil.petro.eshop.db;

import com.oil.petro.eshop.entity.Category;
import javax.annotation.PostConstruct;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

/**
 * @author db
 */
public class DataInitializer {
    
    @Autowired
    private SessionFactory sessionfactory;
    
    private boolean isInit = false;
    
    public void init() {
        if (!isInit) return;
        Category category = new Category("Oleje");
        sessionfactory.getCurrentSession().merge(category);
        category = new Category("Smary");
        sessionfactory.getCurrentSession().merge(category);
        category = new Category("Paliwa");
        sessionfactory.getCurrentSession().merge(category);
        category = new Category("Płyny");
        sessionfactory.getCurrentSession().merge(category);
    }

    public void setIsInit(boolean isInit) {
        this.isInit = isInit;
    }
    
}
